/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.hqueue.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeeplus.common.utils.PageBean;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.queue.entity.Queue;
import com.jeeplus.modules.queue.mapper.QueueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.hqueue.entity.Hqueue;
import com.jeeplus.modules.hqueue.mapper.HqueueMapper;

/**
 * 排队记录Service
 * @author azj
 * @version 2024-10-10
 */
@Service
@Transactional(readOnly = true)
public class HqueueService extends CrudService<HqueueMapper, Hqueue> {
	@Autowired
	private HqueueMapper hqueueMapper;
	public Hqueue get(String id) {
		return super.get(id);
	}
	
	public List<Hqueue> findList(Hqueue hqueue) {
		return super.findList(hqueue);
	}
	
	public Page<Hqueue> findPage(Page<Hqueue> page, Hqueue hqueue) {
		return super.findPage(page, hqueue);
	}
	
	@Transactional(readOnly = false)
	public void save(Hqueue hqueue) {
		super.save(hqueue);
	}
	
	@Transactional(readOnly = false)
	public void delete(Hqueue hqueue) {
		super.delete(hqueue);
	}

	public PageBean <Hqueue> findPageList(Page<Hqueue> page, Hqueue hqueue) {
		PageBean<Hqueue> pageBean = new PageBean<>();
		if(StringUtils.isNotBlank(hqueue.getBeginComeTime()))
			hqueue.setBeginComeTime(hqueue.getBeginComeTime()+" 00:00:00");
		if(StringUtils.isNotBlank(hqueue.getEndComeTime()))
			hqueue.setEndComeTime(hqueue.getEndComeTime()+" 23:59:59");
		PageHelper.startPage(page.getPageNo(), page.getPageSize());
		List<Hqueue> list = hqueueMapper.findPageList(hqueue);
		PageInfo <Hqueue> pageInfo = new PageInfo<>(list);
		pageBean.setCrurentNum(page.getPageNo());
		pageBean.setPageSize(page.getPageSize());
		pageBean.setTotalNum((int) pageInfo.getTotal());
		pageBean.setTotalPageSize(pageInfo.getPages());
		pageBean.setDatas(pageInfo.getList());
		return pageBean;
	}
}